﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using BCDto.Trading.SaleShoppingCart;
using BCTMSRESTful.Configs;
using BCService.Utils;
using BCService.Trading.SaleShoppingCart;

namespace BCTMSRESTful.Controllers.Management.Trading.ShoppingCart
{
    /// <summary>
    /// 销售购物车
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class SaleShoppingCartController : ManagementBaseController
    {
        private readonly ISaleShoppingCartService saleShoppingCartService;

        public SaleShoppingCartController(ISaleShoppingCartService saleShoppingCartService)
        {
            this.saleShoppingCartService = saleShoppingCartService;
        }

        #region 修改销售购物车商品价格（客服议价完成时修改价格使用）
        /// <summary>
        ///  修改销售购物车商品价格（客服议价完成时修改价格使用）
        /// </summary>
        /// <param name="saleShoppingCartId">销售购物车Id</param>
        /// <param name="requestDto">销售购物车信息</param>
        /// <response code="200">修改销售购物车商品价格成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{sale_shopping_cart_id}")]
        [Log("修改销售购物车")]
        [ProducesResponseType(typeof(SaleShoppingCartDto), 200)]
        public IActionResult Put([FromRoute(Name = "sale_shopping_cart_id")]long saleShoppingCartId, [FromBody]SaleShoppingCartBargainRequestDto requestDto)
        {
            SaleShoppingCartPutDto putDto = requestDto.As<SaleShoppingCartPutDto>();
            putDto.SaleShoppingCartId = saleShoppingCartId;
            return StatusCode((int)HttpStatusCode.OK, this.saleShoppingCartService.Update(putDto));
        }
        #endregion

        #region 获取销售购物车
        /// <summary>
        ///  获取销售购物车
        /// </summary>
        /// <param name="saleShoppingCartId">销售购物车Id</param>
        /// <response code="200">获取销售购物车</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{sale_shopping_cart_id}")]
        [ProducesResponseType(typeof(SaleShoppingCartDto), 200)]
        public IActionResult Get([FromRoute(Name = "sale_shopping_cart_id")]long saleShoppingCartId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.saleShoppingCartService.Get(saleShoppingCartId));
        }
        #endregion

        #region 获取销售购物车（分页）
        /// <summary>
        ///  获取销售购物车（分页）
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取销售购物车（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<SaleShoppingCartDto>), 200)]
        public IActionResult Query(
            [FromRoute(Name = "user_id")]long userId,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "sort_name")]string sortName,
            [FromQuery(Name = "ascending")]bool? ascending,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10)
        {
            return StatusCode((int)HttpStatusCode.OK, this.saleShoppingCartService.Query(userId,start, end, sortName, ascending, index, size));
        }
        #endregion
    }
}
